Skip to content

test: add tmux-driven TUI e2e scenarios for Monitor - #4086

Open
chengluyu wants to merge 35 commits into
feat/monitor-toolfrom
test/monitor-tui-e2e
Open

chengluyu wants to merge 35 commits into
feat/monitor-toolfrom
test/monitor-tui-e2e

Conversation

@chengluyu

@chengluyu chengluyu commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator
中文版

需求或 Bug

基于 #4085。为 Monitor 工具补充在真实 TUI 中运行的端到端测试。复用 #4069 的 tmux 测试框架;在 #4069 合并前,本 PR 的 diff 也包含那两个文件,#4069 合并后会同步 main,diff 只剩本 PR 自己的改动。

Bug 复现步骤

N/A

根本原因

N/A

代码变更

 apps/kimi-code/test/e2e/
~├── tui-sandbox.ts               # 新增 monitor(可带 timeout / persistent)、foreground、stopMonitor、
~│                                #   waitForMonitor、monitorOutput 步骤;运行时按描述查找 monitor 的 task id;
~│                                #   startFakeService(模拟远程服务);scenario 可传环境变量,
~│                                #   上下文提供 workDir 和 relaunch(用 --continue 重启同一会话)
+└── tui-monitor.e2e.test.ts      # 16 个 Monitor 场景

场景(通过 KIMI_CODE_EXPERIMENTAL_MONITOR=1 打开开关):

  • 基础:事件唤醒空闲的智能体;轮次进行中到达的事件在下一步送达;传入 monitor 的 task_id 时 WaitFor 在它输出时返回;不传 task_id 的 WaitFor 等待构建完成,不因 monitor 输出返回;输出过多的 monitor 被停止,模型收到原因。
  • 远程服务状态(后台任务 + WaitFor 做不到:它们只在命令结束时报告一次):每次状态变化都单独唤醒智能体;服务不可达时唤醒智能体;服务恢复后智能体用 TaskStop 停止 monitor,之后不再有事件。
  • 来自真实用例(Claude Code 文档、博客、GitHub issue):
    • 开发服务器日志:每个新错误唤醒一次,不重复送达已送过的行
    • 事件未被消费时产生的行,在消费后合并为一批送达
    • CI 监视退出:最后的行先于失败通知送达,stderr 不进入事件
    • 超过单批上限(50 行)的突发输出:保留最新的行,<event omitted="10">,TUI 显示省略数,TaskOutput 能读到完整日志
    • 恶意日志行(</event></notification>…、&、超长行)只作为数据出现在事件中
    • 到达 timeout 时只发一次通知、进程被结束,之后可用 persistent 重新开启
    • WaitFor 指定一个 monitor 时,不会被另一个 monitor 的事件结束
    • 退出时 monitor 进程被结束;--continue 恢复会话后回放事件行且不会自动开始新轮次

行为变化与受影响用户

无——只有测试。与现有 e2e 一样需要主动开启:只在设置 KIMI_E2E=1 且 PATH 中有 tmux 时运行,否则跳过,默认的 vitest 和 CI 不受影响。

KIMI_E2E=1 pnpm --filter @moonshot-ai/kimi-code exec vitest run test/e2e/tui-monitor.e2e.test.ts

Requirement or Bug

Stacked on #4085. Adds end-to-end tests that drive the real TUI for the Monitor tool. It reuses the tmux harness from #4069; until #4069 merges, this PR's diff also contains those two files. Once #4069 lands, main will be merged in and the diff will shrink to this PR's own changes.

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

 apps/kimi-code/test/e2e/
~├── tui-sandbox.ts               # adds monitor (with timeout / persistent), foreground, stopMonitor,
~│                                #   waitForMonitor and monitorOutput steps; a monitor's task id is looked up
~│                                #   by description at run time; startFakeService (a stand-in remote service);
~│                                #   scenario takes env vars, and its context has workDir and relaunch
~│                                #   (restart into the same session with --continue)
+└── tui-monitor.e2e.test.ts      # 16 Monitor scenarios

Scenarios (the flag is turned on with KIMI_CODE_EXPERIMENTAL_MONITOR=1):

  • Basics: an event wakes an idle agent; an event that arrives mid-turn reaches the next step; WaitFor with a monitor's task_id returns when it prints; WaitFor without a task_id waits for the build and is not ended by monitor output; a flooding monitor is stopped and the model hears why.
  • Remote service status (background tasks + WaitFor cannot do this: they report once, when the command ends): every status change wakes the agent separately; an unreachable service wakes the agent; once the service is healthy the agent stops the monitor with TaskStop, and no events follow.
  • From real use cases (Claude Code docs, blog posts, GitHub issues):
    • dev-server log: one wake per new error, and lines already delivered are not sent again
    • lines printed while an event is undelivered arrive together as one batch after it is consumed
    • a CI watch that exits: its last lines arrive before the failure notice, and stderr stays out of events
    • a burst larger than one batch (50 lines): the newest lines are kept, <event omitted="10">, the TUI shows the omitted count, and TaskOutput has the full log
    • hostile log lines (</event></notification>…, &, an overlong line) appear only as data inside the event
    • at its timeout a monitor sends one notice and its process is killed; it can then be re-armed with persistent
    • WaitFor on one monitor is not ended by another monitor's event
    • quitting kills the monitor process; resuming with --continue replays the event rows and starts no new turn

Behavior Changes and Affected Users

None — tests only. The suite is opt-in like the existing e2e tests: it runs only with KIMI_E2E=1 and tmux on PATH, and skips otherwise, so default vitest runs and CI are unchanged.

KIMI_E2E=1 pnpm --filter @moonshot-ai/kimi-code exec vitest run test/e2e/tui-monitor.e2e.test.ts

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

# Conflicts:
#	.changeset/shorter-wait-for.md
#	packages/agent-core-v2/src/agent/tools/task/task-wait/taskWaitTool.ts
@changeset-bot

changeset-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e88e8fd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T20:12:50.544878Z e88e8fd New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@e88e8fd
npx https://pkg.pr.new/@moonshot-ai/kimi-code@e88e8fd

commit: e88e8fd

@chengluyu

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 0ab2b3cd92

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chengluyu

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 37380a8dc3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chengluyu

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cdc8ba7b18

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/kimi-code/test/e2e/tui-monitor.e2e.test.ts Outdated
@chengluyu

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chengluyu

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant